package com.unicom.room.service;

import java.util.List;

import com.unicom.room.mapper.RoomMapper;
import com.unicom.room.model.Room;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RoomService {

	@Autowired
	private RoomMapper roomMapper;
	
	/**
	 * 查询所有房间信息
	 * @return
	 */
	public List<Room> listRooms() {
		return roomMapper.listRooms();
	}
	
    /**
     * 保存房间信息
     * @param room
     * @throws Exception
     */
	public void insertRoom(Room room) throws Exception {
		roomMapper.insertRoom(room);
	}
	
	/**
	 * 修改房间信息
	 * @param room
	 * @throws Exception
	 */
	public void updateRoom(Room room) throws Exception {
		roomMapper.updateRoom(room);
	}
	
	/**
	 * 删除房间
	 * @throws Exception
	 */
	public void deleteRoom(int id) throws Exception {
		roomMapper.deleteRoom(id);
	}
	
	/**
	 * 判断房号是否已存在
	 * @param roomNo
	 * @return
	 */
	public boolean isRoomNoExists(String roomNo) {
		List<String> list = roomMapper.getRoomByNo(roomNo);
		if(null == list || list.size() < 1) {
			return false;
		}
		return true;
	}

}
